package com.qf.wemedia.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.common.goods.GoodsState;
import com.qf.common.page.PageInfo;
import com.qf.common.page.PageUtils;
import com.qf.entity.dto.Goods;
import com.qf.entity.po.LoginMerchant;
import com.qf.service.GoodsService;
import com.qf.service.GoodsSkuService;
import com.qf.service.OrdersService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import javax.annotation.Resource;


@RequestMapping("goods")
@Controller
public class GoodsController {

    @Resource
    GoodsService goodsService;

    /**
     * 前往商品页面，携带商品类型数据和商品信息以及分页信息
     */
    @RequestMapping("list")
    public String toGoodsList(Model model, LoginMerchant loginMerchant, @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        //获取商品列表并分页
        QueryWrapper<Goods> goodsWrapper = new QueryWrapper<>();
        goodsWrapper.lambda()
                .eq(Goods::getMerchantId,loginMerchant.getId())
                .eq(Goods::getStatus, GoodsState.UP.getCode())
                .orderByDesc(Goods::getCreateTime);
        PageInfo<Goods> pageInfo = PageUtils.getPageList(currentPage, goodsWrapper, goodsService);
        model.addAttribute("goodsList",pageInfo.getPageRecords());
        model.addAttribute("pageCounts",pageInfo.getPageCounts());
        return "goods/list";
    }





}
